<template>
    <div class="signUpQueryIndex">

        <van-row>
            <van-form ref="queryForm">
                <span class="field_title">身份证号</span>
                <van-field
                        v-model="idCard"
                        label=""
                        placeholder="请输入查询的身份证号"
                        clearable
                        :rules="idCardRules"
                ></van-field>
                <span class="field_title">报考项目</span>
                <van-radio-group v-model="projectId" direction="horizontal" style="padding:10px 15px;">
                    <van-radio name="1">学历</van-radio>
                    <van-radio name="2">人社部资格证书</van-radio>
                </van-radio-group>
            </van-form>
        </van-row>
        <div style="margin: 16px;text-align: center;">
            <van-button round block type="info" native-type="submit" v-if="!isSubmit" @click="handleQuery"  class="btn">立 即 搜 索</van-button>
            <van-loading type="spinner" color="#1989fa" v-else/>
        </div>
        <div>
            <van-popup v-model="show" closeable>
                <div style="width: 200px;padding: 40px;font-size: 20px;font-weight: bold;border-radius: 20px;">
                    <span v-if="auditStatus == 0">已报名，等待审核</span>
                    <span v-if="auditStatus == 2">
                        已报名，审核失败，请重新补充资料
                        <span @click="updateInfo" style="color: blue">点击进行跳转到修改资料页面</span>
                    </span>
                    <span v-if="auditStatus == 1">
                        报名成功，
                        <span @click="forwardStudy" style="color: blue">点击跳转到学习平台</span>
                    </span>
                </div>
            </van-popup>
        </div>
    </div>
</template>

<script>
    import {identityIdCard} from '@/utils/validate'
    import {getStudentByIdCardAndProject} from '@/api/school'
    import {Toast} from "vant";
    export default {
        name: "signUpQueryIndex",
        data(){
            return {
                projectId: '1',
                studentInfo: undefined,
                auditStatus: 2,
                show: false,
                idCard: '',
                isSubmit: false,
                idCardRules: [
                    { required: true, message: ''},
                    // 自定义校验规则
                    {
                        validator: value => {
                            return identityIdCard(value)
                        },
                        message: '请输入正确格式的身份证号',
                        trigger: 'onBlur'
                    }
                ],
            }
        },
        methods: {
            forwardStudy(){
                this.show = false
            },
            updateInfo(){
                this.show = false
                if(this.projectId == 1){ // 学历查询与修改
                    this.$router.push({name: 'signUpEducationUpdateIndex',query: this.studentInfo})
                }else if(this.projectId == 2){ // 资格证书修改
                    // Toast("资格证书修改");
                    this.$router.push({name: 'signUpQualificationCertificateUpdateIndex',query: this.studentInfo})
                }
            },
            showPopup() {
                this.show = true;
            },
            handleQuery(){
                this.$refs.queryForm.validate().then(() =>{
                    this.isSubmit = true;
                    this.studentInfo = undefined;
                    // console.log(this.projectId)
                    let queryData = {
                        idCard: this.idCard,
                        projectId: this.projectId
                    }
                    getStudentByIdCardAndProject(queryData).then(resp=>{
                        if(resp.code == 200 && resp.data){
                            this.studentInfo = resp.data;
                            console.log("学生数据==========",resp);
                            this.auditStatus = resp.data.auditStatus
                            this.isSubmit = false;
                            this.showPopup();
                        }else{
                            Toast('无学生的报名信息')
                            this.isSubmit = false;
                        }
                    })
                }).catch(()=>{
                    //验证失败
                    this.isSubmit = false
                    return this.dialogNotifyError("请补充信息之后再提交");
                })
            },
        },
        created() {
            this.$store.commit('setTitleName','报名查询')
        }
    }
</script>

<style scoped>
    .field_title{display:block;text-align: left;padding: 15px 15px 0px 15px;}
    .btn{background: #CCCCCC;border: none;border-radius: 0px;color: black;padding-bottom: 10px;}
    span{display: block;padding-top: 10px;}
</style>
